﻿using Gx.Common;
using Gx.Common.Core;
using Gx.Dal.Manage;
using Gx.Model;
using Gx.Model.Entity;
using Gx.Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;


namespace Gx.Bll.Manage
{
    public class LKIncidentalsBll
    {
    
        ///// <summary>
        ///// 分页列表
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //public PagedList<LKIncidentals> GetLKIncidentalsPageList(LKIncidentalsInput input)
        //{
        //    LKIncidentalsDal dal = new LKIncidentalsDal();
        //    return dal.GetLKIncidentalsPageList(input);
        //}

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public List<LKIncidentals> GetLKIncidentalss()
        {
            LKIncidentalsDal dal = new LKIncidentalsDal();
            return dal.GetAll().ToList();
        }

        /// <summary>
        /// 新增杂费设置
        /// </summary>
        /// <param name="lKIncidentals"></param>
        /// <returns></returns>
        public ReturnModel AddLKIncidentals(LKIncidentals lKIncidentals)
        {
            LKIncidentalsDal dal = new LKIncidentalsDal();

            var any = dal.AnyName(lKIncidentals.CostType);
            if (any)
            {
                return new ReturnModel { Success = false, Msg = "名称已存在" };
            }


            lKIncidentals.CreateTime = DateTime.Now;
            lKIncidentals.CreateUserId = LoginHelper.GetUserId();
            lKIncidentals.CreateUser = LoginHelper.UserName();
            var result= dal.Insert(lKIncidentals);
            return new ReturnModel { Success = result, Msg = result ? "新增成功" : "新增失败" };
        }

        /// <summary>
        /// 编辑杂费设置
        /// </summary>
        /// <param name="lKIncidentals"></param>
        /// <returns></returns>
        public bool EditLKIncidentals(LKIncidentals lKIncidentals)
        {
            LKIncidentalsDal dal = new LKIncidentalsDal();
            var cus = dal.Get(lKIncidentals.Id);
            if (cus == null)
            {
                return false;
            }
            lKIncidentals.CreateTime = cus.CreateTime;
            lKIncidentals.CreateUserId = cus.CreateUserId;
            lKIncidentals.CreateUser = cus.CreateUser;
            return dal.Update(lKIncidentals);
        }

        /// <summary>
        /// 删除杂费设置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteLKIncidentals(int id)
        {
            LKIncidentalsDal dal = new LKIncidentalsDal();
            return dal.DeleteById(id);
        }
    }
}

